package com.example.hystrix;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;

public class TestObservableCommand {

    public static void main(String[] args) {

        Observable<String> ob=new ObservableCommandHelloWorld("Evan").observe();
        ob.subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                System.out.println("action1 observe() "+s);
            }
        });
        ob.subscribe(new Subscriber<String>() {
            @Override
            public void onCompleted() {
                System.out.println("Subscriber() completed");
            }

            @Override
            public void onError(Throwable throwable) {
                System.out.println("Subscriber() "+ throwable.getMessage());
            }

            @Override
            public void onNext(String s) {
                System.out.println("subscribe observe() "+s);
            }
        });

        /**
         * toObservable(): 同样返回Observable对象，也代表了操作多个结果，但它返回的是一个cold observale
         * 不允许有多个订阅者， 不然报错： command executed multiple times - this is not permitted
         */
        Observable<String> ob1=new ObservableCommandHelloWorld("evan").toObservable();
        ob1.subscribe(new Subscriber<String>() {
            @Override
            public void onCompleted() {
                System.out.println("toObservable() completed");
            }

            @Override
            public void onError(Throwable throwable) {
                System.out.println("toObservable() "+throwable.getMessage());
            }

            @Override
            public void onNext(String s) {
                System.out.println("subscribe toObservable() "+ s);
            }
        });

    }
}
